<.subheader>
  <:path>
    ~/<.subheader_path_link live_patch to={~p"/endpoints"} team={@team}>endpoints</.subheader_path_link>/{@show_endpoint.name}
  </:path>
  <.subheader_link team={@team} to={~p"/access-tokens"} text="access tokens" fa_icon="key" />
  <.subheader_link team={@team} live_patch to={~p"/endpoints/#{@show_endpoint.id}/edit"} text="edit" fa_icon="edit" />
</.subheader>
<section class="mx-auto container pt-3 tw-flex tw-flex-col tw-gap-4">
  <div>
    id: {@show_endpoint.token}
  </div>

  <p class="text-muted tw-whitespace-pre-wrap tw-text-sm">{@show_endpoint.description}</p>

  <div :if={@show_endpoint.enable_auth == false}>
    <.alert variant="warning">
      <strong>Authentication not enabled!</strong>
      <br />
      <span>
        Authentication has not been enabled for this endpoint, and may pose a security risk.
      </span>
    </.alert>
  </div>

  <div class="tw-w-full tw-bg-zinc-800 tw-p-4 tw-rounded-lg tw-min-h-[100px]">
    <span class="tw-block">
      {case @show_endpoint.language do
        :bq_sql -> "BigQuery SQL"
        :ch_sql -> "ClickHouse SQL"
        :pg_sql -> "Postgres SQL"
        :lql -> "Logflare Query Language"
      end}
    </span>
    <code class="tw-whitespace-pre-wrap tw-text-sm tw-text-white">
      {@show_endpoint.query}
    </code>
  </div>

  <div>
    <ul class="list-group tw-text-sm">
      <li class="list-group-item">
        <strong>max rows:</strong> {@show_endpoint.max_limit}
      </li>
      <li class="list-group-item">
        <strong>caching:</strong> {if @show_endpoint.cache_duration_seconds ==
                                        0,
                                      do: "disabled",
                                      else:
                                        inspect(@show_endpoint.cache_duration_seconds) <>
                                          " seconds"}
      </li>
      <li class="list-group-item">
        <span :if={@show_endpoint.cache_duration_seconds > 0}>
          <strong>cache warming:</strong> {@show_endpoint.proactive_requerying_seconds} seconds
        </span>
      </li>
      <li class="list-group-item">
        <span><strong>query sandboxing:</strong> {if @show_endpoint.sandboxable, do: "enabled", else: "disabled"}</span>
      </li>
      <li class="list-group-item">
        <span><strong>redact PII:</strong> {if @show_endpoint.redact_pii, do: "enabled", else: "disabled"}</span>
      </li>
      <li :if={@show_endpoint.labels} class="list-group-item">
        <span><strong>labels:</strong> {@show_endpoint.labels}</span>
      </li>
    </ul>
  </div>

  <div :if={@parsed_result}>
    <p>
      <button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
        Expand query
      </button>
    </p>
    <div class="collapse" id="collapseExample">
      <div class="card card-body">
        <code class="tw-whitespace-pre-wrap">
          {maybe_redact_query(@parsed_result.expanded_query, @redact_pii)}
        </code>
      </div>
    </div>
  </div>

  <.run_query_form {assigns} />
  <.run_query_result {assigns} />

  <div :if={@show_endpoint.sandboxable} class="tw-mt-8 tw-border-t tw-border-gray-700 tw-pt-8">
    <.run_sandbox_query_form {assigns} />
    <.run_sandbox_query_result {assigns} />
  </div>

  <h3>Call your endpoint</h3>
  <div class="tw-bg-zinc-800 tw-rounded tw-p-2 tw-flex tw-flex-col tw-gap-2">
    <code class="tw-whitespace-pre-line">
      # By UUID
      curl "{"https://api.logflare.app" <> ~p"/api/endpoints/query/#{@show_endpoint.token}"}" \
      -H 'X-API-KEY: YOUR-ACCESS-TOKEN' \
      -H 'Content-Type: application/json; charset=utf-8' <span :if={@declared_params != []}>\</span>
      <span :if={@declared_params != []}>-G {Enum.map(@declared_params, fn p -> "-d \"#{p}=VALUE\"" end) |> Enum.join(" ")}</span>
    </code>

    <code :if={@show_endpoint.enable_auth} class="tw-whitespace-pre-line">
      # By name
      curl "{"https://api.logflare.app" <> ~p"/api/endpoints/query/#{@show_endpoint.name}"}" \
      -H 'X-API-KEY: YOUR-ACCESS-TOKEN' \
      -H 'Content-Type: application/json; charset=utf-8' <span :if={@declared_params != []}>\</span>
      <span :if={@declared_params != []}>-G {Enum.map(@declared_params, fn p -> "-d \"#{p}=VALUE\"" end) |> Enum.join(" ")}</span>
    </code>

    <code class="tw-whitespace-pre-line">
      # With per-request PII redaction
      curl "{"https://api.logflare.app" <> ~p"/api/endpoints/query/#{@show_endpoint.token}"}" \
      -H 'X-API-KEY: YOUR-ACCESS-TOKEN' \
      -H 'LF-ENDPOINT-REDACT-PII: true' \
      -H 'Content-Type: application/json; charset=utf-8' <span :if={@declared_params != []}>\</span>
      <span :if={@declared_params != []}>-G {Enum.map(@declared_params, fn p -> "-d \"#{p}=VALUE\"" end) |> Enum.join(" ")}</span>
    </code>
  </div>
</section>
